package cn.cjxy.web.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * session的持久化也叫钝化与活化
 * ● 钝化：从内存到磁盘
 * ● 活化：从磁盘到内存
 *
 * @author huangjie
 * @date 2025/9/27
 */
@WebServlet("/create")
public class SessionCreate extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        Person person = new Person("1", "张三");
        //将对象存入session
        req.getSession().setAttribute("person", person);
        resp.getWriter().println("访问成功.....会话id"+req.getSession().getId());
        resp.getWriter().print(person);
    }
}
